<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../../component/layui/css/layui.css"/>
    <link href="../../admin/css/pearSelect.css" rel="stylesheet"/>
    <link href="../../admin/css/pearCommon.css" rel="stylesheet"/>
    <link href="../../admin/css/dtree.css" rel="stylesheet"/>
    <style>
           body{
               margin: 20px;
           }
    </style>
</head>
<body>
<form class="layui-form" action="javascript:void(0);">
    <div  class="mainBox">
        <div class="layui-row" style="margin: 15px;">
            <div class="layui-col-md6 layui-col-sm6 layui-col-xs6">
                <div class="layui-form-item">
                    <label class="layui-form-label">账户</label>
                    <div class="layui-input-block">
                        <input type="text" name="username" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md6 layui-col-sm6 layui-col-xs6">
                <div class="layui-form-item">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md6 layui-col-sm6 layui-col-xs6">
                <div class="layui-form-item">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-block">
                        <input type="text" name="realName" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md6 layui-col-sm6 layui-col-xs6">
                <div class="layui-form-item">
                    <label class="layui-form-label">邮箱</label>
                    <div class="layui-input-block">
                        <input type="email" name="email" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>

            <div class="layui-col-md6 layui-col-sm6 layui-col-xs6">
                <div class="layui-form-item">
                    <label class="layui-form-label">电话</label>
                    <div class="layui-input-block">
                        <input type="phone" name="mobile" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md6 layui-col-sm6 layui-col-xs6">
                <div class="layui-form-item">
                    <label class="layui-form-label">性别</label>
                    <div class="layui-input-block">
                        <input type="text" name="sex" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md6 layui-col-sm6 layui-col-xs6">
                <div class="layui-form-item">
                    <label class="layui-form-label">角色</label>
                    <div class="layui-input-block">
                        <select name="roles" xm-select="select4">
                            <option th:each="role:${roles}" th:value="${role.id}" th:text="${role.name}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-col-md6 layui-col-sm6 layui-col-xs6">
                <div class="layui-form-item">
                    <label  class="layui-form-label">部门</label>
                    <div class="layui-input-block">
                        <ul id="selectParent" class="dtree" data-id="0" data-value="0"></ul>
                    </div>
                </div>
            </div>

        </div>
    </div>
    <div  class="bottom">
        <div class="button-container">
            <button class="layui-btn layui-btn-sm" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-sm layui-btn-primary">重置</button>
       </div>
    </div>
</form>

<script src="../../component/layui/layui.js"></script>
<script>
    //Demo
    layui.use(['form','pearFly','pearLayer','pearSelect','operate','dtree'], function(){
        var form = layui.form;
        var operate = layui.operate;
        var dtree = layui.dtree;

        dtree.renderSelect({
            elem: "#selectParent",
            url: "/system/dept/tree",
            method:'get',
            selectInputName: {nodeId: "deptId", context: "name"},
            skin: "layui",
            dataStyle: "layuiStyle",
            dataFormat: "list",
            response:{message:"msg",statusCode:0, treeId: "id", parentId: "pid", title: "name"},  //修改response中返回数据的定义
            selectInitVal: "1"
        });

        //监听提交
        form.on('submit(formDemo)', function(data){

            operate.save('/system/user/save',data.field,'userTable');

        });
    });
</script>
</body>
</html>